package com.base.web;

import java.util.Arrays;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.base.dubbo.service.UserDubboService;
import com.base.model.User;
import com.base.service.UserService;
import com.base.util.JsonUtil;
import com.base.util.JsonUtil.JsonTypeEnum;

@RequestMapping("/")
@Controller
public class IndexAction extends BaseAction {
	
	@Autowired
	private UserService userService;
	@Autowired
	private UserDubboService userDubboService;
	@Resource(name="logJmsTemplate")
	private JmsTemplate logJmsTemplate;
	
	@RequestMapping("hello")
	public String hello(ModelMap model) {
		model.addAttribute("list", Arrays.asList(new String[]{"zhangsan", "lisi", "xiaoming"}));
		return "hello";
	}
	
	@ResponseBody
	@RequestMapping("addUser")
	public User addUser() {
		User user = userService.addUser("zhangsan", "123456");
		System.out.println(user);
		return user;
	}
	
	@ResponseBody
	@RequestMapping("getUser")
	public User getUser() {
		User user = userDubboService.getUserById(1);
		System.out.println(user);
		user = userService.getCacheUserById(1);
		System.out.println(user);
		logJmsTemplate.convertAndSend(JsonUtil.use(JsonTypeEnum.Jackson).toJsonStr(user));
		return user;
	}

}
